const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
require('dotenv').config();
const db = require('./models');

const app = express();


// 使用 CORS 中间件
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

//这个是同步数据库
db.sequelize.sync()
  .then(() => {
    console.log('Synced successfully');
  })
  .catch(err => {
    console.log('Synced error: ' + err.message);
  });

//这里导入路由
const userRouters = require('./routes/user.router');
const dashboardRouters = require('./routes/dashboardRouter');
const tableRouers = require('./routes/table.router'); 
const gameRouters = require('./routes/game.router');
const luckRouters = require('./routes/luck.router');


app.use('/api', userRouters);
app.use('/api', dashboardRouters);
app.use('/api', tableRouers);
app.use('/api', gameRouters);
app.use('/api', luckRouters);

// const requestAPI = require('./services/requestAPI');

// 监听所有 IP 地址，端口为 3000
app.listen(3000, '0.0.0.0', () => {
  // requestAPI.getAccess_token();
  // requestAPI.getWxCodeUnlimit();
  console.log('服务已启动...server listening on port 3000');
});
